<!DOCTYPE HTML>
<html>
<head>
	<title>tincase</title>
	<meta http-equiv="Content-Type"content="text/html; charset=utf-8">
	<link rel="stylesheet"type="text/css"href="css/normalize.css">
	<link rel="stylesheet"type="text/css"href="css/main.css">
	<script type="text/javascript"src="js/jquery-1.4.2.min.js"></script>
</head>
<body>
	<div id="content">
		<h2>tinturbulenz</h2>
		
		<div class="html-control control-checkbox">
			<span class="control-title">Enable Debug Rendering</span>
			<input type="checkbox" id="checkbox01"/>
		</div>
		
		<div id="engine-object">
			<div id="engine-wrapper">
				<!--
				HTML to create a plugin or canvas instance.
				Supplied by'tz_engine_div'variable.
				-->
				
        <script type="text/javascript">
            if (window.ActiveXObject)
            {
                document.write('<object id="turbulenz_game_loader_object" classid="CLSID:49AE29B1-3E7D-4f62-B3D2-D6F7C7BEE728" width="100%" height="100%">');
                document.write('<param name="type" value="application/vnd.turbulenz" \/>');
                document.write('<p>You need the Turbulenz Engine for this.');
                document.write('<\/p>');
                document.write('<\/object>');
            }
            else
            {
                // browser supports Netscape Plugin API
                document.write('<object id="turbulenz_game_loader_object" type="application/vnd.turbulenz" width="100%" height="100%">');
                document.write('<p>You need the Turbulenz Engine for this.');
                document.write('<\/p>');
                document.write('<\/object>');
            }
        </script>
				<script type="text/javascript">
					var pw = $('#engine-object').width();
					// Calculate aspect ratio
					var ph = pw * 9/16;

					// Resize element for plugin or canvas to fill
					$('#engine-wrapper').css({
						height: ph,
						width: pw
					});
				</script>
			</div>
		</div>
		<p id="game-details" class="game-info"></p>
		<span id="versions" class="game-info">
			<span class="sdk">
				SDK version:
				<span id="sdk_version"></span>
				<span id="sdk_alert"></span>
			</span>
			<span class="engine">
				Engine version:
				<span id="engine_version">0.0.0</span>
				<span id="engine_alert"></span>
			</span>
		</span>
		<span class="copyright game-info">TinCase &copy; 2014 <a href="mailto:7inpham@gmail.com">7inpham</a></span>
	</div>
	<script>
		var config = {
			title: "TinCase",
			version: "0.5",
			sdk_version: "0.28.0.0",
			language: "English",
			allowAlerts: false
		};
		document.title = config.title + " powered By Turbulenz";
		document.getElementById("sdk_version").innerHTML = config.sdk_version;
		document.getElementById("game-details").innerHTML = config.title + " | v" + config.version + " | " + config.language;
	</script>
	
	<!--begin'tz_include_js'variable-->
    

	<!--end'tz_include_js'variable-->
	
	<script type="text/javascript">
	// ----------------------------------------
	// Embedded code and startup code.
	// Supplied by 'tz_startup_code' variable.
	// ----------------------------------------
    

        window.onload = function ()
        {
            var loader = document.getElementById('turbulenz_game_loader_object');
            var config = {
                url: 'tincase.tzjs'
            };

            // Engine unload
            var previousOnBeforeUnload = window.onbeforeunload;
            window.onbeforeunload = function ()
            {
                try {
                    loader.unloadEngine();
                } catch (e) {
                }
                if (previousOnBeforeUnload) {
                    previousOnBeforeUnload.call(this);
                }
            };

            

            function findBestVersion(request, availableVersions)
            {
                var reqNumbers = request.split(".");
                var candidate;

                for (var vIdx = 0; vIdx < availableVersions.length; vIdx += 1)
                {
                    var ver = availableVersions[vIdx];
                    var verNumbers = ver.split(".");

                    // Check the version has the correct major and minor

                    if ((verNumbers[0] !== reqNumbers[0]) ||
                        (verNumbers[1] !== reqNumbers[1]))
                    {
                        continue;
                    }

                    // If there is already a candidate, compare point and build

                    if (candidate)
                    {
                        if (verNumbers[2] > candidate[2])
                        {
                            candidate = verNumbers;
                            continue;
                        }
                        if ((verNumbers[2] === candidate[2]) &&
                            (verNumbers[3] > candidate[3]))
                        {
                            candidate = verNumbers;
                            continue;
                        }
                    }
                    else
                    {
                        candidate = verNumbers;
                    }
                }

                if (candidate)
                {
                    candidate = candidate.join(".");
                }
                return candidate;
            }

            var now = Date.now || function () { return new Date().valueOf(); };
            var loadDeadline = now() + 5 * 1000;  // 5 seconds
            var loadInterval = 500;               // 0.5 seconds

            var attemptLoad = function attemptLoadFn()
            {
                // Check plugin and load engine
                var err = 0;
                if (!loader) {
                    err = "no loader DOM element";
                }
                if (err === 0 &&
                    !loader.loadEngine &&
                    loader.hasOwnProperty &&
                    !loader.hasOwnProperty('loadEngine')) {
                    err = "loader has no 'loadEngine' property";
                }
                if (err === 0 &&
                    !loader.getAvailableEngines &&
                    !loader.hasOwnProperty('getAvailableEngines')) {
                    err = "no 'getAvailableEngines'. Plugin may be "
                            + "an older version.";
                }

                if (err === 0)
                {
                    var availableEngines = loader.getAvailableEngines();
                    var samplesVersion = '0.28';
                    var requestVersion =
                        findBestVersion(samplesVersion, availableEngines);
                    if (!requestVersion)
                    {
                        err = "No engines installed that are compatible with "
                                + "version " + samplesVersion;
                    }
                    else
                    {
                        config.version = requestVersion;
                    }
                }

                if (err === 0)
                {
                    // Plugin is in place
                    if (!loader.loadEngine(config))
                    {
                        window.alert("Call to loadEngine failed");
                    }
                    return;
                }

                // Continue to wait for the plugin
                if (loadDeadline >= now()) {
                    window.setTimeout(attemptLoad, loadInterval);
                } else {
                    window.alert("No Turbulenz Loader found ("+err+")");
                }
            };
            attemptLoad();

        };  // window.onload()
	</script>
</body>
</html>